//
//  HomePageActionCell.swift
//  HappyEat
//
//  Created by ctx2016 on 17/1/8.
//  Copyright © 2017年 陌路是我. All rights reserved.
//

import UIKit


class HomePageActionCell: UITableViewCell {
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.setUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

    }
    override func layoutSubviews() {
        super.layoutSubviews()
    }

}
extension HomePageActionCell{
    func setUI(){
        let itemWidth:CGFloat = 55.0
        let space:CGFloat = (k_Wide - 32 - (55 * 5))/4
        let namesArray = ["美食","KTV","门票","足疗","写真"]
        let imageNames = ["ic_food","ic_ktv","ic_ticket","ic_Z","ic_photo"]
        for i in 0 ..< namesArray.count{
            let imageView:UIImageView = UIImageView.init(image: UIImage.init(named: imageNames[i]))
            let title:UILabel = UILabel.init()
            self.contentView.addSubview(imageView)
            self.contentView.addSubview(title)
            imageView.snp.makeConstraints({ (make) in
                make.left.equalTo(16 + (CGFloat(i) * itemWidth) + (CGFloat(i) * space))
                make.size.equalTo(CGSize.init(width: itemWidth, height: itemWidth))
                make.top.equalTo(12)
            })
            title.snp.makeConstraints({ (make) in
                make.left.equalTo(16 + (CGFloat(i) * itemWidth) + (CGFloat(i) * space))
                make.size.equalTo(CGSize.init(width: itemWidth, height: 14))
                make.top.equalTo(imageView.snp.bottom).offset(8)
            })
            title.textAlignment = .center
            title.text = namesArray[i]
            title.font = UIFont.systemFont(ofSize: 14)
            let cTrol:UIControl = UIControl.init()
            self.contentView.addSubview(cTrol)
            cTrol.backgroundColor = .clear
            cTrol.tag = 1000+i
            cTrol.addTarget(self, action: #selector(controlAction(_:)), for: .touchUpInside)
        }
    }
    func controlAction(_ button:UIControl){
        switch button.tag {
        case 1000:
            print("meishi")
        case 1001:
            print("KTV")
        case 1002:
            print("门票")
        case 1003:
            print("足浴")
        case 1004:
            print("写真")
        default:
            print("？")
        }
    }
}
